package com.open.cinema.system.controller;


import com.open.cinema.system.model.UserInfo;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Slf4j
@Controller
public class ShiroController {

    @PostMapping("/login")
    public @ResponseBody String login(UserInfo user){
        Subject subject = SecurityUtils.getSubject();
        UsernamePasswordToken usernamePasswordToken = new UsernamePasswordToken(user.getUserCode(), user.getPassword());

        try {
            subject.login(usernamePasswordToken);
        } catch (AuthenticationException e) {

            e.printStackTrace();
        }
        return  "loginSuccess";
    }

}
